export const isMaxTwoDecNum = (num) => {
    // 判断是否最多两位小数
    if(!num && num!==0) {
        // null undefined
        return false;
    }
    if(typeof(num) === 'number') {
        if(isNaN(num)) {
            // NaN
            return false;
        }
        else if(num.toString().split('.')[1] && num.toString().split('.')[1].length > 2) {
            // 超过2位小数
            return false;
        }
        return true
    }
    else {
        // 有可能是字符串
        if(!/^\d+(\.\d+)?$/.test(num)) {
            // 是否是数字 包括小数
            return false;
        }
        else if(num.toString().split('.')[1] && num.toString().split('.')[1].length > 2) {
            return false;
        }
        return true;
    }
}

export const isInteget = (numArr) => {
    // 判断是否是整数
    for(let i = 0, len = numArr.length; i<len ; i++) {
        const reg = /^\d+$/;
        if(!reg.test(numArr[i])) {
            return false;
        }
    }
    return true;
}

export const isPosInteger = (num) => {
    // 判断是否正整数
    return /^[1-9]\d*$/.test(num)
}

export const isNumber = (num) => {
    // 判断是否是数字
    return /(^[1-9]\d*$)/.test(num)
}

export const isPhone = (phone) => {
    // 判断是否手机号
    return /^1[23456789]\d{9}$/.test(phone)
}
export const isEmail = (email) => {
    // 判断是否邮箱
    return /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/.test(email)
}
export const isBase64 = (str) => {
    if(!str) return;
    return str.toString().indexOf('base64,')>-1
}

export const isEmojiCharacter = (substring) => {
    if(!substring) return false;
    substring = substring.toString();
    const reg = new RegExp("[~#^$@%&!?%*]", 'g');
    if (substring.match(reg)) {
        return true;
    }
    for (let i = 0; i < substring.length; i++) {
        let hs = substring.charCodeAt(i);
        if (0xd800 <= hs && hs <= 0xdbff) {
            if (substring.length > 1) {
                let ls = substring.charCodeAt(i + 1);
                let uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;
                if (0x1d000 <= uc && uc <= 0x1f77f) {
                    return true;
                }
            }
        } else if (substring.length > 1) {
            let ls = substring.charCodeAt(i + 1);
            if (ls == 0x20e3) {
                return true;
            }
        } else {
            if (0x2100 <= hs && hs <= 0x27ff) {
                return true;
            } else if (0x2B05 <= hs && hs <= 0x2b07) {
                return true;
            } else if (0x2934 <= hs && hs <= 0x2935) {
                return true;
            } else if (0x3297 <= hs && hs <= 0x3299) {
                return true;
            } else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs == 0x3030
                || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b
                || hs == 0x2b50) {
                return true;
            }
        }
    }
}